package com.dd.filter;

import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.TimerTask;
import javax.servlet.ServletContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.StaleObjectStateException;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate.HibernateOptimisticLockingFailureException;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.dd.entity.*;
import com.dd.dao.*;
import com.dd.service.*;

public class SystemTimerTask extends TimerTask {
	private ApplicationContext ctx;
	private static final Log logger = LogFactory.getLog(SystemTimerTask.class);
	private static boolean isRunning = false;
	ServletContext application;
	public SystemTimerTask(ServletContext sc) {
		application=sc;
		this.ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
		
	
		
		System.out.println("timer init........................");
	}

	public void run() {
		try {
			if (!isRunning) {
		//		application.removeAttribute("ht");
		//		System.out.println("timer runnin........................");
				isRunning = true;				
			}else{
				
				logger.info("[timer]-The last task is not over");
				
			}
			isRunning = false;
			
		} catch (Exception e) {
			e.printStackTrace();
			this.logger.error(e.toString());
			isRunning = false;
		}

	}
}
